//
// Created by zhupi on 2024/8/31.
//

#include "work_tree_widget.h"
#include <QVBoxLayout>

WorkTreeWidget::WorkTreeWidget(QWidget *parent) : QWidget(parent)
{

}

void WorkTreeWidget::Initial()
{
    this->setMaximumWidth(300);
    QVBoxLayout *mainVbox = new QVBoxLayout;
    mainVbox->setContentsMargins(0,0,0,0);
    treeView_ = new WorkTree(this);
    mainVbox->addWidget(treeView_);
    this->setLayout(mainVbox);
    InitWidget();
    treeView_->expandAll();
}

void WorkTreeWidget::InitWidget()
{
    // 创建一个标准项模型
    treeMolde_ = new QStandardItemModel;

    // 设置列标题
//    treeMolde_->setHorizontalHeaderLabels(QStringList() << "Item" << "Description");

    // 创建根节点
    QStandardItem *rootItem = treeMolde_->invisibleRootItem();

    // 创建一些项
    QStandardItem *item1 = new QStandardItem("Item 1");
    QStandardItem *item2 = new QStandardItem("Item 2");
    QStandardItem *item3 = new QStandardItem("Item 3");

    // 为每个项添加子项
    item1->appendRow(new QStandardItem("SubItem 1.1"));
    item1->appendRow(new QStandardItem("SubItem 1.2"));
    item2->appendRow(new QStandardItem("SubItem 2.1"));
    item3->appendRow(new QStandardItem("SubItem 3.1"));
    item3->appendRow(new QStandardItem("SubItem 3.2"));

    // 将项添加到根节点
    rootItem->appendRow(item1);
    rootItem->appendRow(item2);
    rootItem->appendRow(item3);

    // 将模型设置到QTreeView
    treeView_->setModel(treeMolde_);

    // 设置QTreeView的样式表，显示网格线
//    treeView_->setStyleSheet(
//            "QTreeView::item {"
//            "    border: 1px solid lightgray;"
//            "}"
//    );

    // 调整列宽
//    treeView_->header()->setSectionResizeMode(QHeaderView::ResizeToContents);

    // 显示QTreeView
    treeView_->setWindowTitle("QTreeView Example");
    treeView_->resize(400, 300);
    treeView_->show();


}


